package com.sinosoft.service8;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.StringReader;
import java.util.Properties;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;



public class XmlFilterImpl implements XmlFilter {

	

	@Override
	public boolean xmlFilter(String key, String value,String createXml) {
		
		//Properties prop = new Properties();
		String nodeName = null;
		String textContent = null;
		try {
			DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
			
			//prop.load(XmlFilterImpl.class.getClassLoader().getResourceAsStream(
			//		"xml.properties"));
			//String filterlmx = prop.getProperty("lmx");
			//File xml=new File(filterlmx);
			StringReader stringReader=new StringReader(createXml);
			InputSource inputSource=new InputSource(stringReader);
			DocumentBuilder db = dbf.newDocumentBuilder();
			//InputStream in=new FileInputStream(xml);
			//System.out.println();
			//System.out.println(xml);
			Document doc = db.parse(inputSource);
		
			Element root = doc.getDocumentElement();
			
			System.out.println(root.getNodeName());
			NodeList childNodes1 = root.getChildNodes();
			Node item1 = childNodes1.item(1);
			Node item = item1.getChildNodes().item(1);
			
			    
			 
			
			
			nodeName=item.getNodeName();
			textContent=item.getTextContent();
			System.out.println(nodeName);
			System.out.println(textContent);
			
		
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		if (key.equals(nodeName) && value.equals(textContent))
			return true;
		else
			return false;
	}

}
